package com.bignerdranch.android.ecar.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;

import com.bignerdranch.android.ecar.Adapter.FaultAdapter;
import com.bignerdranch.android.ecar.Bean.FaultBean;
import com.bignerdranch.android.ecar.R;

import java.util.ArrayList;
import java.util.List;

public class FaultActivity extends BaseActivity implements View.OnClickListener {
    private ListView mListView;
    private List<FaultBean> mData;
    private ImageButton fault_back;
    private ImageButton fault_add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fault);
        initView();
        initData();
        mListView.setAdapter(new FaultAdapter(this,mData));
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(FaultActivity.this,FaultResultActivity.class);
                intent.putExtra("license",mData.get(position).getLicense());
                startActivity(intent);
            }
        });

    }

    private void initView() {
        fault_back = (ImageButton) findViewById(R.id.fault_back);
        fault_add = (ImageButton) findViewById(R.id.fault_add);
        mListView = (ListView) findViewById(R.id.fault_list);

        fault_back.setOnClickListener(this);
        fault_add.setOnClickListener(this);
    }

    private void initData(){
        mData = new ArrayList<>();
        for(int i = 0;i < 10;i++){
            FaultBean bean = new FaultBean("豫AE8888","正常","宝马X"+i,""+(i+1),"1000",i+"");
            mData.add(bean);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fault_back:

                finish();
                break;
            case R.id.fault_add:

                Intent intent = new Intent(this,AddCarActivity.class);
                startActivity(intent);
                break;
        }
    }
}
